<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: ListOpenId.php 425 2011-01-05 10:30:30Z steen.rabol $
 *
 */

Prado::using('Application.Common.Data.PortalUserOpenIdRecord');

class ListOpenId extends PortalSystemPage
{
	public function onInit($param)
	{
		parent::onInit($param);

		if(!$this->IsPostBack)
		{
			$data = PortalUserOpenIdRecord::GetOpenIDsByUser($this->User->id);
			if(count($data))
			{
				$this->repOpenId->dataSource =  $data;
				$this->repOpenId->dataBind();
			}
			else
			{
				$this->pnlListOpenId->Visible	= false;
				$this->pnlListOpenId->Enabled	= false;

				$this->pnlNoListOpenId->Enabled	= true;
				$this->pnlNoListOpenId->Visible	= true;
			}
		}
	}

	public function attachButtonClicked($sender,$param)
	{
		if($this->Page->IsValid)
		{
		}
	}

	public function checkOpenIdUrl($sender,$param)
	{
		$uid = PortalUserOpenIdRecord::GetUserId($param->Value);

		if($uid == 0)
		{
			$param->IsValid = false;
		}
		else
		{
			$param->IsValid = true;
		}
	}

	public function cancelButtonClicked($sender,$param)
	{
		$this->gotoDefaultPage();
	}

	public function removeOpenId($id)
	{
		if(count(PortalUserOpenIdRecord::GetOpenIDsByUser($this->User->id)) > 1)
		{
			PortalUserOpenIdRecord::finder()->deleteByPk($id);
		}
		else
		{
			$this->reportError(0,Prado::localize("Can not remove the only OpenId attached to your account"));
		}

	}

	public function ItemCommand($sender,$param)
	{
		PortalUtil::Debug($param);
		switch($param->CommandName)
		{
			case 'removeOpenId':
				$this->removeOpenId($param->CommandParameter);
				break;
		}
	}
}
?>